package alp.starcode.user.service;

import alp.starcode.framework.database.entity.User;
import alp.starcode.framework.database.mapper.UserMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserBo {

    @Autowired
    UserMapper userMapper;

    public User login(User user) {
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getUsername, user.getUsername());
        queryWrapper.eq(User::getPassword, user.getPassword());
        return userMapper.selectOne(queryWrapper);
    }

    /**
     *
     * @param user
     * @return
     */
    public Boolean register(User user) {
        user.setCreateTime(System.currentTimeMillis());
        user.setUpdateTime(System.currentTimeMillis());
        return userMapper.insert(user) > 0;
    }
}
